<!--
 * @Author: 王明明834578987 10266004+wang-mingming-834578987@user.noreply.gitee.com
 * @Date: 2024-08-29 10:59:23
 * @LastEditors: 王明明834578987 10266004+wang-mingming-834578987@user.noreply.gitee.com
 * @LastEditTime: 2024-10-25 10:37:48
 * @FilePath: \ft-apply-admin\src\views\applicationDetails\Modals\InternalPushModal.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <BasicModal :show="show" :showFooter="true" title="内推详情" width="30%" :widthComfirm="true" @comfirm="comfirm">
    <template #content>
      <CommonForm @radioChange="radioChange" :formList="formList" ref="formRef" labelWidth="110px"></CommonForm>
    </template>
  </BasicModal>
</template>

<script setup lang='ts'>
import { watch, ref } from "vue"
import BasicModal from './BasicModal.vue';
import CommonForm from "@/views/applicationDetails/CommonForm.vue";
import type { IndexFormItem } from "@/views/ApplicationDetails/application-type.ts";
import { updateRecommendsResumes } from "@/api/application-details/index.ts";
const show = ref<boolean>(false);
import { comStores } from '@/store/common/comStore';
import { message } from "ant-design-vue";
const store = comStores();

const formList = ref<IndexFormItem[]>([
  {
    label: "内推", name: "isRecommends", value: "", component: 'radio', options: [
      { label: "是", value: 0 },
      { label: "否", value: 1 },
    ]
  },
  { label: "内推人", name: "recommendsName", value: "", component: 'input', show: true },
  { label: "内推人手机号", name: "recommendsPhone", value: "", component: 'input', show: true },
])
const formRef = ref<any>(null);
watch(() => show.value, (val) => {
  if (val) {
    const { isRecommends, recommendsName, recommendsPhone, processSort } = store.currentResume
    formList.value[0].value = isRecommends
    formList.value[1].value = recommendsName
    formList.value[2].value = recommendsPhone;
    if (isRecommends === 1) {
      formList.value[1].show = false
      formList.value[2].show = false;
    }
    formList.value.forEach(el => {
      el.disabled = processSort >= 11
    })
  }
})
const comfirm = async () => {
  const { resumeId } = store.currentResume;
  const { userName } = store.userInFor
  const res = await formRef.value.submitForm();
  let param: any = {

  };
  res.forEach(el => {
    param[el.name] = el.value
  })
  param.resumesId = resumeId
  param.operator = userName
  const data = await updateRecommendsResumes(param);
  if (data && data.code === '10000') {
    message.success("修改成功");
    show.value = false
    store.getResumeInfo(resumeId)
  } else {
    message.error(data.msg)
  }
  console.log(data, 'data')
}
const radioChange = (val) => {
  console.log(val)
  formList.value[1].show = val.value === 0
  formList.value[2].show = val.value === 0
}

defineExpose({ show })
</script>

<style lang="less" scoped>
:deep(.ant-form-item-control-input) {
  // padding-top: 6px;
}
</style>
